<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="__STATIC__/js/jquery.js"></script>
    <script src="__STATIC__/layui/layui.js"></script>
    <script type="text/javascript" src="__STATIC__/x-admin/js/xadmin.js"></script>
    <link rel="stylesheet" href="__STATIC__/x-admin/css/font.css">
    <link rel="stylesheet" href="__STATIC__/x-admin/css/xadmin.css">
    <link rel="stylesheet" href="__STATIC__/layui/css/layui.css">
</head>
<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="#">财务管理</a>
        <a href="#">收支管理</a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:window.location.reload();" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div style="height: 50px"></div>
<div style="width: 500px">
    <form class="layui-form" action="" name="add" onclick="return false" id="expenses_receipts">
        <input type="hidden" value="{$info->id}" name="id">
        <div class="layui-form-item">
            <label class="layui-form-label">申请人</label>
            <div class="layui-input-block">
                <input type="text" name="applicant" value="{$info->applicant}" placeholder="申请人" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">金额</label>
            <div class="layui-input-block">
                <input type="text" name="money" value="{$info->money}" placeholder="金额" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">类别</label>
            <div class="layui-input-block">
                <select name="type">
                    <option value="1" {if $info.type == "收入"} selected {/if} >收入</option>
                    <option value="2" {if $info.type == "支出"} selected {/if} >支出</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <textarea name="remarks" id="remarks" placeholder="50个字以内" class="layui-textarea">{$info->remarks}</textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" id="insert">立即修改</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
</body>
<script>
    $("#insert").click(function(){
        if(!$("input[name=applicant]").val()){
            layer.msg('申请人不能为空',{icon:5,time:2000});
            return;
        }
        if(!$("input[name=money]").val()){
            layer.msg('金额不能为空',{icon:5,time:2000});
            return;
        }
        if(!checkRate()){
            layer.msg('请输入正确的金额',{icon:5,time:2000});
            return;
        }
        if(!$("#remarks").val()){
            layer.msg('备注不能为空',{icon:5,time:2000});
            return;
        }
        $.ajax({
            url:"{:url('/expenses_receipts/update')}",
            type:"post",
            data:$("#expenses_receipts").serialize(),
            dataType:"json",
            success:function(res){
                if(res.code){
                    layer.msg(res.msg,{icon:1,time:2000});
                }else{
                    layer.msg(res.msg,{icon:5,time:2000});
                }
            }
        });
    });
    //金额判断
    function checkRate() {
        var re = /^[0-9]+.?[0-9]*$/;
        var number = $("input[name=money]").val();
        if (!re.test(number)) {
            return false;
        }
        return true;
    }
</script>
</html>